//廉洁从业
var api = require('../util/api.js');
Page({
  data: {

  },

  onLoad: function (options) {
    this.setData({
      page: api.page(10),
      dataList: [],
      params: {

      }
    });
    this.onReachBottom();
  },
  onPullDownRefresh() {
    this.setData({
      page: api.page(10),
      dataList: []
    });
    this.loadList();
  },
  onReachBottom() {
    this.loadList();
  },
  loadList() {
    var _this = this;
    var params = _this.data.params;
    var page = _this.data.page;
    api.get(api.url.ljcyList, params, page).then(res => {
      page.setTotal(res.total);
      if (res.rows.length == 0) {
        this.setData({
          hasData: false
        })
      } else {
        _this.setData({
          hasData: true,
          dataList: _this.data.dataList.concat(res.rows)
        });
      }
    })
  },
  searchInputAction: function (e) {
    let _this = this
    let value = e.detail.value
    if (value.length != 0) {
      _this.data.params['superviseName'] = value;
    } else {
      _this.data.params['superviseName'] = '';
    }
    _this.setData({
      dataList: [],
      page: api.page(10)
    });
    _this.loadList();
  },
  longPress(e) {
    var ljcyId = e.currentTarget.dataset.id;
    api.chain({
      ljcyId: ljcyId
    });
    wx.showActionSheet({
      itemList: ['编辑'],
      success: function (res) {
        if (res.tapIndex == 0) {
          wx.navigateTo({
            url: `./edit`
          });
        }
      },
      fail: function (res) {
        console.log(res.errMsg)
      }
    })
  },
  goView(e) {
    var ljcyId = e.currentTarget.dataset.id;
    api.chain({
      ljcyId: ljcyId
    });
    wx.navigateTo({
      url: "./view"
    });
  },
  goAdd: function () {
    api.chain({});
    wx.navigateTo({
      url: "./edit"
    });
  }
})